package com.taotie.mapper;

import com.github.pagehelper.Page;
import com.taotie.annotation.AutoFill;
import com.taotie.dto.DishPageQueryDTO;
import com.taotie.entity.Dish;
import com.taotie.enumeration.OperationType;
import com.taotie.vo.DishVO;
import lombok.Data;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    @Data
    class DishModel {
        //菜品名称
        private String name;

        //菜品价格
        private BigDecimal price;

        //描述信息
        private String description;
    }

    /**
     * 根据分类id查询菜品数量
     *
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    @AutoFill(OperationType.INSERT)
    void insert(Dish dish);

    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     * 根据id主键删除菜品数据
     *
     * @param ids
     */

    void deleteByIds(List<Long> ids);

    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);


    /**
     * 动态条件查询菜品
     *
     * @param dish
     * @return
     */
    List<Dish> list(Dish dish);

    /**
     * 根据套餐id查询菜品
     * @param setmealId
     * @return
     */
    @Select("select * from dish d left join setmeal_dish sd on d.id = sd.dish_id "
            + "where sd.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    /**
     * 查询该用户的偏好菜品
     * @param dishId
     * @return
     */
    @Select("select * from dish where id=#{dishId}")
    List<Dish> getAll(Long dishId);

    @Select("select dish_id from dish_case where openid=#{openid}")
    List<Long> getDishId(String openid);

    @Select("select name,price,description from dish where status=1")
    List<DishModel> dishAll();

    @Select("select id from dish where status=1")
    long[] dishId();
}
